﻿

Imports System.Runtime.CompilerServices


Imports System.ServiceModel.Syndication


Imports Microsoft.DPE.Samples.PictureProvider

Imports System.Xml.Serialization

Public Module SimpleListExtensionHelper



    ''' <summary>
    '''  Adds the necessary item extensions for SLE
    ''' </summary>
    ''' <param name="feed"></param>
    ''' <param name="list"></param>
    ''' <remarks></remarks>
    <Extension()> _
    Public Sub AddSLEItemExtensions(ByVal feed As SyndicationFeed, ByVal list As List(Of Picture))
        For i = 0 To feed.Items.Count - 1
            Dim currentItem = feed.Items(i)
            currentItem.ElementExtensions.Add("title", NamespaceUris.PSDNamespace, list(i).Title)
            currentItem.ElementExtensions.Add("rating", NamespaceUris.PSDNamespace, list(i).Rating)
            currentItem.ElementExtensions.Add("ratingText", NamespaceUris.PSDNamespace, list(i).RatingText)

        Next
    End Sub

    '    /// <summary>
    '    /// Adds the necessary element extensions for SLE
    '    /// </summary>
    '    /// <param name="feed"></param>
    '    public static void AddSLEFeedExtensions(this SyndicationFeed feed)
    '    {
    '        XNamespace ns = NamespaceUris.CFNamespace;

    '        // 
    '        feed.ElementExtensions.Add(new XElement(ns + "treatAs", "list", new XAttribute(XNamespace.Xmlns + "cf", ns)));

    '        feed.ElementExtensions.Add(
    '            // <cf:listinfo>
    '            new XElement(ns + "listinfo", new XAttribute(XNamespace.Xmlns + "cf", ns),
    '            // <cf:sort label="Title" default="true" />
    '                new XElement(ns + "sort",
    '                    new XAttribute("label", "Title"),
    '                    new XAttribute("default", "true")),
    '            // <cf:sort ns="http://www.microsoft.com/psd" element="rating" data-type="number" label="Rating" />
    '                new XElement(ns + "sort",
    '                    new XAttribute("ns", NamespaceUris.PSDNamespace),
    '                    new XAttribute("element", "rating"),
    '                    new XAttribute("data-type", "number"),
    '                    new XAttribute("label", "Rating")),
    '            // <cf:group ns="http://www.microsoft.com/psd" element="ratingText" label="Rating" />
    '                new XElement(ns + "group",
    '                    new XAttribute("ns", NamespaceUris.PSDNamespace),
    '                    new XAttribute("element", "ratingText"),
    '                    new XAttribute("label", "Rating"))));
    '    }

    <Extension()> _
    Public Sub AddSLEFeedExtensions(ByVal feed As SyndicationFeed)

        '<cf:treatAs>list</cf:treatAs> 
        feed.ElementExtensions.Add(<cf:treatAs xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005">list</cf:treatAs>)

        '<cf:listinfo xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005">
        '  <cf:sort label="Title" default="true" />
        '  <cf:sort ns="http://www.microsoft.com/psd" element="rating" data-type="number" label="Rating" />
        '  <cf:group ns="http://www.microsoft.com/psd" element="ratingText" label="Rating" />
        '</cf:listinfo>
        feed.ElementExtensions.Add(<cf:listinfo xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005">
                                       <cf:sort label="Title" default="true"/>
                                       <cf:sort ns=<%= NamespaceUris.PSDNamespace %> element="rating" data-type="number" label="Rating"/>
                                       <cf:group ns=<%= NamespaceUris.PSDNamespace %> element="ratingText" label="Rating"/>
                                   </cf:listinfo>)



    End Sub


    

End Module
